<?php
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
header("Content-type: text/xml;  charset=TIS-620");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
//XML Header
header("content-type:text/xml"); 
createKmlFile();
function parseToXML($htmlStr)
{ 

$xmlStr=str_replace('<','&lt;',$htmlStr); 

$xmlStr=str_replace('>','&gt;',$xmlStr); 

$xmlStr=str_replace('"','&quot;',$xmlStr); 

$xmlStr=str_replace("'",'&#39;',$xmlStr); 

$xmlStr=str_replace("&",'&amp;',$xmlStr); 

return $xmlStr; 

} 
function createKmlFile(){
$q=$_GET["q"];

$con = mysql_connect('localhost', 'root', '');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("aris", $con);
mysql_query("SET NAMES UTF8");
$sql="SELECT * FROM student WHERE id_st = '".$q."'";

$result = mysql_query($sql);
echo '<?xml version="1.0" encoding="utf-8"?>';  
//echo "<input name='name_st' type='text' value='" ;
header("Content-type: text/xml");
echo "<CATALOG>";

//<table id='box-table-a' cellspacing='0' cellpadding='0'>
//<tr>
//<th>Firstname</th>
//<th>Lastname</th>
//<th>Age</th>
//<th>Hometown</th>
//<th>Job</th>
//</tr>";

while($row = mysql_fetch_array($result))
  {

  
  
  echo 		'<cd>';
	echo '<id1>'.parseToXML($row['name_st']).'</id1>';
	echo '<id2>'.parseToXML($row['class_st']).'</id2>';
	echo '<id3>'.parseToXML($row['Pre_st']).'</id3>';
	echo '<id4>'.parseToXML($row['sname_st']).'</id4>';
       
    echo '</cd>';
}
echo '</CATALOG>';

 // echo "<tr>";
  //echo  $row['name_st'] . "";
  //echo "<td>" . $row['sname_st'] . "</td>";
  //echo "<td>" . $row['class_st'] . "</td>";
  //echo "<td>" . $row['date_st'] . "</td>";
 // echo "<td>" . $row['id'] . "</td>";
 // echo "</tr>";
  //}
//echo "'>";
//echo "</CATALOG>";

mysql_close($con);
}
?>